//
//  XHOrderViewController.m
//  testApp
//
//  Created by ColdMountain on 2016/12/1.
//  Copyright © 2016年 ColdMountain. All rights reserved.
//

#import "XHOrderViewController.h"
#import "XHOftenGoPlaceViewController.h"
#import "XHSideViewController.h"

#import "Services.h"

#import <AFNetworking.h>
#import <MBProgressHUD.h>
#import <UIImageView+CornerRadius.h>
#import <TZImagePickerController.h>

@interface XHOrderViewController ()<TZImagePickerControllerDelegate>
@property (weak, nonatomic) IBOutlet UILabel *test;
@property (weak, nonatomic) IBOutlet UIWebView *ui_webView;
@property (weak, nonatomic) IBOutlet UIView *ui_navView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *la_navViewBottom;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *la_selectTimeViewBottom;
@property (weak, nonatomic) IBOutlet UIButton *ui_twoRowBtn;
@property (weak, nonatomic) IBOutlet UIButton *ui_threeRowBtn;
@property (weak, nonatomic) IBOutlet UIView *ui_btnBGView;
@property (weak, nonatomic) IBOutlet UIView *ui_shadowView;
@property (weak, nonatomic) IBOutlet UIView *ui_view;

@property (assign, nonatomic) CGRect cg_view;
@property (strong, nonatomic) CALayer *ca_view;

@property (weak, nonatomic) IBOutlet UIImageView *image;

@property (strong, nonatomic) NSMutableArray *imageArray;
@property (strong, nonatomic) UIImageView *imageView;
@property (strong, nonatomic) UIButton *button;
@property (strong, nonatomic) NSTimer *timer;
@end

@implementation XHOrderViewController

- (void)dealloc
{
    [[NSNotificationCenter alloc]removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.ui_btnBGView.layer.masksToBounds=YES;
    self.ui_btnBGView.layer.cornerRadius=20;

    self.ui_shadowView.layer.masksToBounds=YES;
    self.ui_shadowView.layer.cornerRadius=20;
    self.ui_shadowView.layer.borderWidth=1;
    self.ui_shadowView.layer.borderColor=[ColorManager colorWithHexString:@"#5cb3f6"].CGColor;
    self.ui_twoRowBtn.selected=YES;
    [self.ui_twoRowBtn setTitleColor:[ColorManager colorWithHexString:@"#5cb3f6"] forState:UIControlStateSelected];
    [self.ui_twoRowBtn setTitleColor:[ColorManager colorWithHexString:@"#B3B3B3"] forState:UIControlStateNormal];
    
    [self.ui_threeRowBtn setTitleColor:[ColorManager colorWithHexString:@"#5cb3f6"] forState:UIControlStateSelected];
    [self.ui_threeRowBtn setTitleColor:[ColorManager colorWithHexString:@"#B3B3B3"] forState:UIControlStateNormal];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(showNavView) name:@"showNavView" object:nil];
    UIBarButtonItem *leftItem=[[UIBarButtonItem alloc] initWithTitle:@"测试" style:UIBarButtonItemStylePlain target:self action:@selector(customerService)];
    self.navigationItem.leftBarButtonItem=leftItem;
}

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    if ([self.ui_twoRowBtn isSelected])
    {
        CGRect frame=self.ui_shadowView.frame;
        frame.origin.x=self.ui_twoRowBtn.frame.origin.x;
        frame.size.width=self.ui_twoRowBtn.frame.size.width;
        self.ui_shadowView.frame=frame;
    }
    else
    {
        CGRect frame=self.ui_shadowView.frame;
        frame.origin.x=self.ui_threeRowBtn.frame.origin.x;
        frame.size.width=self.ui_threeRowBtn.frame.size.width;
        self.ui_shadowView.frame=frame;
    }
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden=YES;
//    if (self.timer==nil)
//    {
//        self.timer=[NSTimer scheduledTimerWithTimeInterval:.3 target:self selector:@selector(makeSnow) userInfo:nil repeats:YES];
//    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden=NO;
}
- (IBAction)swipeAction:(id)sender {
    XHSideViewController * viewController = [[XHSideViewController alloc]init];
    viewController.modalPresentationStyle = UIModalPresentationCustom;
    [self presentViewController:viewController animated:NO completion:^{
        
    }];
}
- (IBAction)ceBianLan:(id)sender {
    XHSideViewController * viewController = [[XHSideViewController alloc]init];
    viewController.modalPresentationStyle = UIModalPresentationCustom;
    [self presentViewController:viewController animated:NO completion:^{
        
    }];
}

- (void)customerService
{
    XHSideViewController * viewController = [[XHSideViewController alloc]init];
    viewController.modalPresentationStyle = UIModalPresentationCustom;
    [self presentViewController:viewController animated:NO completion:^{
        
    }];
}

- (IBAction)onClickAction:(id)sender
{
//    WS(weakSelf)
//    [UIView animateWithDuration:.3 animations:^{
//        self.la_navViewBottom.constant=-64;
//        [weakSelf.view layoutIfNeeded];
//        [self goOftenPlay];
//    } completion:^(BOOL finished) {
//    }];
    [self.timer setFireDate:[NSDate distantPast]];
}

- (IBAction)endAction:(id)sender {
//    [self.timer setFireDate:[NSDate distantFuture]];
    [self.timer invalidate];
}

static int i=0;

- (void)makeSnow
{
    AxcRedEnvelope *button;
    button=[[AxcRedEnvelope alloc]initWithFrame:CGRectMake(IMAGE_X, -100, 100, 100)];
    button.tag=i;
//    [button setImage:[UIImage imageNamed:@"red"]forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:@"red"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(redClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
//    [UIView animateWithDuration:3 animations:^{
//        button.frame=CGRectMake(button.frame.origin.x, SCREEN_HEIGHT-200, button.frame.size.width, button.frame.size.height);
//    } completion:^(BOOL finished) {
//        [button removeFromSuperview];
//    }];
    i++;
    [self snowFall:button];
}
- (void)snowFall:(UIButton *)aImageView
{
    UIViewAnimationOptions options = UIViewAnimationCurveLinear | UIViewAnimationOptionAllowUserInteraction;
    [UIView animateWithDuration:5 delay:0 options:options animations:^{
        aImageView.frame = CGRectMake(aImageView.frame.origin.x, SCREEN_HEIGHT-200, aImageView.frame.size.width, aImageView.frame.size.height);
    } completion:^(BOOL finished) {
        [aImageView removeFromSuperview];
    }];
}

- (void)redClick:(AxcRedEnvelope *)button
{
    NSLog(@"%ld",button.tag);
}



///模态视图
- (void)goOftenPlay
{
    XHOftenGoPlaceViewController * viewController = [[XHOftenGoPlaceViewController alloc]init];
    viewController.modalPresentationStyle = UIModalPresentationCustom;
    [self presentViewController:viewController animated:YES completion:^{
        
    }];
}

///导航栏动画
- (void)showNavView
{
    WS(weakSelf)
    [UIView animateWithDuration:.3 animations:^{
        self.la_navViewBottom.constant=0;
        [weakSelf.view layoutIfNeeded];
    } completion:^(BOOL finished) {
    
    }];
}

///按钮动画
- (IBAction)onClickMenuItemAction:(UIButton*)sender
{
//    TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:9 delegate:self];
//    
    // You can get the photos by block, the same as by delegate.
    // 你可以通过block或者代理，来得到用户选择的照片.
//    [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray *photos, NSArray *assets) {
//        
//    }];
//    [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray *photo,NSArray *assets,BOOL isSelectOriginalPhoto){
//        NSLog(@"%@",photo);
//    }];
//    [self presentViewController:imagePickerVc animated:YES completion:nil];
//    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
//    
//    // Set the text mode to show only text.
//    hud.mode = MBProgressHUDModeText;
//    hud.labelText=@"获取数据失败";
//    [hud hide:YES afterDelay:3];
//    
//    [self.ui_twoRowBtn setSelected:NO];
//    [self.ui_threeRowBtn setSelected:NO];
//    [sender setSelected:YES];
//    WS(weakSelf)
//    [UIView animateWithDuration:0.3 animations:^{
//        CGRect frame=weakSelf.ui_shadowView.frame;
//        frame.origin.x=sender.frame.origin.x;
//        frame.size.width=sender.frame.size.width;
//        weakSelf.ui_shadowView.frame=frame;
//    }];
//    if (sender.tag==0)
//    {
//        WS(weakSelf)
//        [UIView animateWithDuration:.3 animations:^{
//            [PromptAction showSuccessPrompt:@"成功"];
//            self.la_selectTimeViewBottom.constant=100;
//            [weakSelf.view layoutIfNeeded];
//        }];
//    }
//    else if (sender.tag==1)
//    {
//        WS(weakSelf)
//        [UIView animateWithDuration:.3 animations:^{
//            self.la_selectTimeViewBottom.constant=150;
//            [weakSelf.view layoutIfNeeded];
//        }];
//    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
